const studentController = require('../../controllers/web/studentController');
const seriesController = require('../../controllers/web/seriesController');
const chapterController = require('../../controllers/web/chapterController');
const workController = require('../../controllers/web/workController');
const homeController = require('../../controllers/web/homeController');
const notifyController = require('../../controllers/web/notifyController');

const oss = require('../../services/ossService');
const tokens = require('../../services/tokenService');

module.exports = app => {
  const express = require('express');
  const router = express.Router();

  router.post('/login', studentController.login);
  router.post('/logout', studentController.logout);
  router.get('/:domain/home', homeController.home);
  router.get('/oss/getOssKey',oss.getOssKey);

  router.all('*',function (req,res,next) {
    tokens.checkToken(req.header('s-token'), function (err,decode) {
      if (err)
        return res.send({code: 50014, message: '身份校验失败'});
      req.decode = decode;
      next()
    })
  });
  router.get('/info', studentController.info);
  router.get('/series/:type', seriesController.list);

  router.get('/chapter/:series', chapterController.list);
  router.get('/chapter/:chapter_id/opened_list', chapterController.opened_list);
  // router.get('/chapter/course/:id', courseController.list);

  router.post('/work/scratch/teach/', workController.getMyWorksList);
  router.post('/work/scratch/create/', workController.getOrgWorksList);

  router.get('/notify',notifyController.getNotify);

  app.use('/student', router);
};
